import 'package:flutter_model_package/CourseClass.dart';
import 'package:flutter_model_package/parse_base.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';

import 'Teacher.dart';

class CourseLesson extends MSParseBase {
  CourseLesson() : super("CourseLesson");

  CourseLesson.cloe() : this();

  @override
  CourseLesson clone(Map<String, dynamic> map) =>
      CourseLesson.cloe()..fromJson(map);

  static Future<List<CourseLesson>> forLessonTea(Teacher tea) async {
    var query = QueryBuilder(CourseLesson())
      ..whereEqualTo("teacher", tea)
      ..includeObject(['teacher', 'location', 'class.branch']);
    var rep = await query.query();
    if (rep.results != null && rep.success) {
      return rep.results.map((e) => e as CourseLesson).toList();
    } else {
      return List.empty();
    }
  }

  static QueryBuilder<CourseLesson> forLessonById(String id) {
    return QueryBuilder(CourseLesson())
      ..whereEqualTo("objectId", id)
      ..includeObject(['teacher', 'location', 'class.branch',"class.course"]);
  }

  static Future<List<CourseLesson>> getstuLesson(CourseClass courseClass)async{
    var q = QueryBuilder(CourseLesson())..whereEqualTo("class", courseClass);
    var rep = await q.query();
    return rep.results.map((e) => e as CourseLesson).toList();
  }

}
